package com.spsy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spsy.pojo.Book;
import com.spsy.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Sokai
 * @Date: 2024/10/23 08:40
 * @Description:
 **/
@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    BookService bookService;

    @PostMapping("/selectList")
    public void selectList(){
        for (Book book : bookService.list()) {
            System.out.println(book);
        }
    }


    @PostMapping("/delBook/{id}")
    public void delBook (@PathVariable("id")Integer id){
        boolean b1 = bookService.removeById(id);
        System.out.println(b1);
    }

    @PostMapping("/updBook/{id}")
    public void updBook(@PathVariable("id")Integer id){
        Book book = new Book();
        book.setName("java");
        book.setPrice(100);
        book.setTitle("很好");
        book.setAuthor("Sokai");
        QueryWrapper<Book> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Book::getId,id);
        boolean update = bookService.update(book, wrapper);
        System.out.println(update);
    }
    @PostMapping("/addBook")
    public void  addBook(){
        Book book = new Book();
        book.setName("呆过");
        book.setPrice(10);
        book.setTitle("good");
        book.setAuthor("Sokai");
        boolean save = bookService.save(book);
        System.out.println(save);
    }
}
